<template>
  <div class="goodsDetail">
    <ContentWrap>
      <div class="table-list-box">
        <el-table
          border
          :height="tableHeight"
          highlight-current-row
          header-row-class-name="table-list-header"
          tooltip-effect="dark"
          style="width: 100%"
          :data="orderGoods"
        >
          <el-table-column type="index" :index="indexMethod" label="序号" width="50" />
          <el-table-column prop="skuCode" label="商品编码" :show-overflow-tooltip="true" />
          <el-table-column prop="skuName" label="商品名称" :show-overflow-tooltip="true" width="180" />
          <el-table-column prop="buyNum" label="购买数量" />
          <el-table-column prop="closeNum" label="实退货数量（售中）" width="140" />
          <el-table-column prop="returnNum" label="实退货数量（售后）" width="140" />
          <el-table-column prop="withCarTime" label="配车时间" />
          <el-table-column prop="transportTime" label="启运时间" />
          <el-table-column label="关闭状态">
            <template slot-scope="scope">{{ formatFeeStatus(scope.row.returnGoodsStatus) }}</template>
          </el-table-column>
          <el-table-column prop="dealPrice" label="成交单价" />
          <el-table-column prop="receivableFee" label="成交金额" />
          <el-table-column prop="closedFee" label="关闭金额" />
          <el-table-column label="发货状态">
            <template slot-scope="scope">{{ formatSendStatus(scope.row.sendStatus) }}</template>
          </el-table-column>
          <el-table-column prop="returnFeeStatus" label="退款状态">
            <template slot-scope="scope">{{ formatGoodsRefundstatus(scope.row.returnFeeStatus) }}</template>
          </el-table-column>
        </el-table>
      </div>
    </ContentWrap>
  </div>
</template>

<script>
import ContentWrap from '@/components/ContentWrap'
import { getDictByType } from '@/api/dataDict'
export default {
  components: {
    ContentWrap
  },
  props: {
    orderGoods: {
      type: Array,
      default: () => { return [] }
    },
    cheight: {
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      feeStatusOption: [],
      sendStatusOption: [],
      goodsRefundstatusOption: [],
      tableHeight: 400,
      dataList: []
    }
  },
  created() {
    this.getDataDict({ type: 'returnGoodsStatus', ditctType: 'RETURNFEESTATUS' })
    this.getDataDict({ type: 'sendStatus', ditctType: 'PRODUCTSENDSTATUS' })
    this.getDataDict({ type: 'returnFeeStatus', ditctType: 'GOODSREFUNDSTATUS' })
  },
  methods: {
    indexMethod(index) {
      return index + 1
    },
    /**
     * 获取数据字典
     */
    getDataDict({ type, ditctType }) {
      const dictTypeCode = ditctType
      const appCode = 'call-center'
      const domainCode = 'marketing'
      const parmas = {
        dictTypeCode,
        appCode,
        domainCode
      }
      getDictByType(parmas).then(res => {
        const data = res.data || []
        if (Array.isArray(data)) {
          // data.forEach((list) => {
          //   list.dictCode = Number(list.dictCode)
          // })
          if (type === 'returnGoodsStatus') this.feeStatusOption = data // 关闭状态
          if (type === 'sendStatus') this.sendStatusOption = data // 发货状态
          if (type === 'returnFeeStatus') this.goodsRefundstatusOption = data // 退款状态
        }
      })
    },
    getDictName(property, dc) {
      if (typeof dc === 'number') {
        dc = dc.toString()
      }
      const dict = this[property] || []
      for (const item of dict) {
        if (item.dictCode === dc) {
          return item.dictName
        }
      }
      return dc === undefined || dc === null ? '--' : dc
    },
    // 关闭状态
    formatFeeStatus(state) {
      return this.getDictName('feeStatusOption', state)
    },
    // 发货状态
    formatSendStatus(state) {
      return this.getDictName('sendStatusOption', state)
    },
    // 退款状态
    formatGoodsRefundstatus(state) {
      return this.getDictName('goodsRefundstatusOption', state)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
